package com.lelefly.base.Validator;

import java.util.regex.Pattern;

import net.sf.json.regexp.RegexpUtils;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import com.lelefly.base.model.ValidateErrors;
import com.lelefly.base.po.LeleflyUser;

@Component
public class LeleflyUserValidator implements BaseValidator{

	@Override
	public boolean isSupport(Class model) {
		// TODO Auto-generated method stub
		if (model.isAssignableFrom(LeleflyUser.class)) {
			return true;
		}
		return false;
	}

	@Override
	public void validator(Object object, ValidateErrors errors) {
		// TODO Auto-generated method stub
		LeleflyUser user = (LeleflyUser) object;
//		if (StringUtils.isEmpty(user.getUsername())|| !Pattern.matches("^[\u4e00-\u9fa5_a-zA-Z0-9]{2,20}",user.getUsername())) {
//			errors.addError("用户名只能是2-20位的中文数字字母下划线");
//		}
		if (StringUtils.isEmpty(user.getPhonenumber())|| !Pattern.matches("^[0-9]{11}",user.getPhonenumber())) {
			errors.addError("请输入11为手机号");
		}
		if (StringUtils.isEmpty(user.getPassword())|| !Pattern.matches("[_a-zA-Z0-9]{2,20}",user.getPassword())) {
			errors.addError("密码只能数字字母下划线");
		}
		
//		if (StringUtils.isEmpty(user.getIdcard())) {
//			errors.addError("身份证不能为空");
//		}
		
	}


}
